//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "UI/Types/Types.h"
#include "UI/Types/UIAction.h"
#include "UI/Types/UpdateWidgetData.h"
#include "UI/Animation/Frame/IFrameAnimation.h"

namespace Engine
{
namespace UI
{


	//
	// UI Screen
	//

	class Screen : public BaseObject
	{
	// types
	public:
		typedef array< FramePtr >	frame_stack_t;

		struct ELockInput
		{
			enum type
			{
				USER		= 0,
				FRAME_ANIM,
				_MASK		= 31
			};
		};


	// variables
	private:
		IFrameAnimationPtr			_frameAnim;
		IFrameAnimationPtr const	_defaultAnim;

		TimerManager		_timer;

		frame_stack_t		_frames;

		UpdateWidgetData	_data;
		//ivec2				_accumDelta;		// in pixels
		float				_touchDelta;		// in mm
		
		uint				_lockInputFlags;

		bool				_needComputeRegion		: 1;
		bool				_redraw					: 1;
		bool				_continuouslyRenderMode : 1;


	// methods
	public:
		Screen (const EngineSubSystemsRef ess);
		~Screen ();


		bool Draw (float timeDelta);
		
		void Redraw ();
		void Refresh ();

		void LockInput (ELockInput::type flag);
		void UnlockInput (ELockInput::type flag);
		bool IsInputLocked () const					{ return _lockInputFlags != 0; }

		bool HasFrames () const						{ return not _frames.Empty(); }

		void SetContinuouslyRender (bool enable)	{ _continuouslyRenderMode = enable; }
		bool IsContinuouslyRenderMode () const		{ return _continuouslyRenderMode; }


		// Frames //
		uint GetStackDepthFor (const FramePtr &frame) const;
		bool IsVisible (const FramePtr &frame) const;

		bool ShowFrame (const FramePtr &frame);
		bool ShowFrame (const FramePtr &frame, const IFrameAnimationPtr &anim);

		bool CloseFrame (const FramePtr &frame);

		bool CloseCurrentFrame ();
		bool CloseCurrentFrame (const IFrameAnimationPtr &anim);

		bool CloseAll ();


		// Events //
		void OnAttached ();
		void OnDetached ();


	private:
		void _UpdateInput ();

		void _OnWindowEvent (const SysEvent &ev);

		void _Action_CloseFrame (Widget *);

		void _OnShowFrameAnimFinished ();
		void _OnCloseFrameAnimFinished ();
	};


}	// UI
}	// Engine